package com.xcw.util;

import java.util.*;

/**
 * @Author bhx
 * @Date 2022/7/13 2:06
 * @Description TODO
 */
public class Collections_ {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("11");
        list.add("222");
        list.add("3333");
        list.add("44");
        System.out.println(list);
        // 自然排序
        Collections.sort(list);
        System.out.println(list);
        // 自定义排序
        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.length()- o2.length();
            }
        });
        System.out.println(list);
        //倒序
        Collections.reverse(list);
        System.out.println(list);
        //随机排序
        Collections.shuffle(list);
        System.out.println(list);
        // 指定下标交换
        Collections.swap(list,0,3);
        System.out.println(list);
        // max返回最大的数
        System.out.println(Collections.max(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.length() - o2.length();
            }
        }));
        // min 最小
        System.out.println(Collections.min(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.length() - o2.length();
            }
        }));
        // 计算某个值 出现的次数 需要提前赋值
        System.out.println(Collections.frequency(list, "11"));
        System.out.println(Collections.frequency(list, "null"));
        // 拷贝值
       List<String> list1 = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            list1.add("");
        }
       Collections.copy(list1,list);
        System.out.println("---- " + Arrays.equals(list.stream().toArray(), list1.stream().toArray()));

        System.out.println("__list1_ "+list1);
        // 替换
        Collections.replaceAll(list,"222","11");
        System.out.println(list);
        Collections.replaceAll(list,"11","奥利给");
        System.out.println(list);

        System.out.println(list.containsAll(Arrays.asList("[a,b,c]")));
        List<String> list2 = Arrays.asList("44","3333");
        System.out.println(list.containsAll(list2));
        System.out.println(list2);
    }
}
